﻿using AutoMapper;
using BW.MesProject.BasicData.Domain.基础;
using BW.MesProject.BasicData.Infrastructure;
using BW.MesProject.Public.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BW.MesProject.BasicData.Host.Controllers
{
    /// <summary>
    /// 供应商管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SupplierController : ControllerBase
    {
        private readonly ISupplierServices supplierServices;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="supplierServices">供应商服务</param>
        public SupplierController(ISupplierServices supplierServices)
        {
            this.supplierServices = supplierServices;
        }

        /// <summary>
        /// 添加或修改供应商
        /// </summary>
        /// <param name="model">供应商模型</param>
        /// <returns>操作结果</returns>
        [HttpPost]
        public ApiResult<int> AddSupplier(SupplierModel model)
        {
            return supplierServices.AddSupplier(model);
        }

        /// <summary>
        /// 删除供应商
        /// </summary>
        /// <param name="id">供应商ID</param>
        /// <returns>操作结果</returns>
        [HttpPut]
        public ApiResult<int> DeleteSupplier(long id)
        {
            return supplierServices.DeleteSupplier(id);
        }

        /// <summary>
        /// 获取所有供应商
        /// </summary>
        /// <returns>供应商列表</returns>
        [HttpGet]
        public ApiResult<List<SupplierModel>> GetAllSupplier()
        {
            return supplierServices.GetAllSupplier();
        }

        /// <summary>
        /// 分页查询供应商
        /// </summary>
        /// <param name="Suppliercode">供应商编码（可选）</param>
        /// <param name="Suppliername">供应商名称（可选）</param>
        /// <param name="pageindex">页码</param>
        /// <param name="pagesize">每页记录数</param>
        /// <returns>分页结果</returns>
        [HttpGet]
        public ApiPaging<SupplierModel> GetSupplier(string? Suppliercode, string? Suppliername, int pageindex , int pagesize )
        {
            return supplierServices.GetSupplier(Suppliercode, Suppliername, pageindex, pagesize);
        }

        /// <summary>
        /// 根据ID获取供应商
        /// </summary>
        /// <param name="id">供应商ID</param>
        /// <returns>供应商信息</returns>
        [HttpGet]
        public ApiResult<SupplierModel> GetSupplierById(long id)
        {
            return supplierServices.GetSupplierById(id);
        }
    }
}
